package club.banyuan;

public class Main {
    public static void main(String[] args) {
        double totalPrice = 0;                  // 所有蛋糕的总价格
        double totalReadyMadeCakePrice = 0;     // ReadyMadeCake的总价格
        int totalReadyMadeCakeQuantity = 0;     // ReadyMadeCake的数量

        Cake[] cakes = new Cake[10];
        // 奇数下标存放OrderCake，偶数下标存放ReadyMadeCake
        for (int i = 0; i < 10; i++) {
            if (i % 2 == 0) {
                cakes[i] = new ReadyMadeCake((int) (Math.random() * 20));
            } else
                cakes[i] = new OrderCake(Math.random() * 20);
        }

        int maxIndex = 0;

        for (int i = 0; i < 10; i++) {
            totalPrice += cakes[i].getPrice();
            if (cakes[i].getPrice() > cakes[maxIndex].getPrice()) {
                maxIndex = i;
            }
            if (i % 2 == 0) {
                totalReadyMadeCakePrice += cakes[i].getPrice();
                totalReadyMadeCakeQuantity += ((ReadyMadeCake) cakes[i]).getQuantity();
            }

        }

        System.out.println("所有蛋糕的总价为" + totalPrice);
        System.out.println("ReadyMadeCake蛋糕的总价为" + totalReadyMadeCakePrice);
        System.out.println("ReadyMadeCake蛋糕的总数量为" + totalReadyMadeCakeQuantity);
        if (maxIndex % 2 == 0) {
            System.out.println("最高价格出售的蛋糕是按数量卖的；有" + ((ReadyMadeCake) cakes[maxIndex]).getQuantity() + "个");
        } else
            System.out.println("最高价格出售的蛋糕是按斤卖的；有" + ((OrderCake) cakes[maxIndex]).getWeightInKG() + "公斤");
    }

}
